package com.jcnet.bizaia.fragment;

import com.amap.api.maps2d.model.LatLng;
import com.jcnet.bizaia.MarkerActivity;
import com.jcnet.bizaia.R;
import com.jcnet.bizaia.bean.DisscussInfoBean;
import com.jcnet.bizaia.bean.MapBean;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

/**
 * @author chenguandong
 * @serial   讨论会想想
 */
public final class DicussDetailFragment extends Fragment implements OnClickListener{
    private static final String KEY_CONTENT = "TestFragment:Content";

    
    private DisscussInfoBean chaChairJson;
    
    private ImageButton mapImageButton;
    
    private ImageButton phoneImageButton;
    
    
    public static DicussDetailFragment newInstance( DisscussInfoBean chaChairJson) {
        DicussDetailFragment fragment = new DicussDetailFragment();


        fragment.chaChairJson = chaChairJson;
        return fragment;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)) {
            //mContent = savedInstanceState.getString(KEY_CONTENT);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       View view = View.inflate(getActivity(), R.layout.disscuss_info, null);
       ((TextView)view.findViewById(R.id.dis_title)).setText(chaChairJson.getTitle());
       ((TextView)view.findViewById(R.id.dis_subTitle)).setText(chaChairJson.getDescribing());
       ((TextView)view.findViewById(R.id.dis_date)).setText(getText(R.string.startDate)+": "+chaChairJson.getBegindate());
       ((TextView)view.findViewById(R.id.dis_adress)).setText(getText(R.string.adress)+": "+chaChairJson.getCraddress());
       ((TextView)view.findViewById(R.id.dis_phone)).setText(getText(R.string.phone)+": "+chaChairJson.getCrtel());
       ((TextView)view.findViewById(R.id.dis_Num)).setText(getText(R.string.peopleNUM)+": "+chaChairJson.getCrnumber()+"");
       ((TextView)view.findViewById(R.id.dis_endDate)).setText(getText(R.string.endDate)+": "+chaChairJson.getEnddate());
       mapImageButton = (ImageButton)view.findViewById(R.id.mapButton);
       phoneImageButton = (ImageButton)view.findViewById(R.id.mapPhone);
       mapImageButton.setOnClickListener(this);
       phoneImageButton.setOnClickListener(this);
       
       return view;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
       // outState.putString(KEY_CONTENT, mContent);
    }


	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.mapButton:
			Intent intent = new Intent(getActivity(), MarkerActivity.class);
			intent.putExtra("mapBean", new MapBean(chaChairJson.getTitle(),chaChairJson.getCraddress()));
			intent.putExtra("lat", chaChairJson.getLat());
			intent.putExtra("lng", chaChairJson.getLng());
			getActivity().startActivity(intent);
			break;
		case R.id.mapPhone:
			//拨打电话  
			Uri uri = Uri.parse("tel:"+chaChairJson.getCrtel().trim());  
			Intent it = new Intent(Intent.ACTION_DIAL, uri);    
			startActivity(it); 
			break;

		default:
			break;
		}
	}
}
